package com.hadwinling.alogriithm.apilearn.source;

import com.hadwinling.alogriithm.apilearn.beans.SensorReading;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @description:
 * @author: hadwinling
 * @time: 2021/2/19 上午11:32
 */

//从集合中读取数据
public class SourceTest1_Collection {

    public static void main(String[] args) throws Exception {
        // 创建执行环境
        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();
        executionEnvironment.setParallelism(1); // 设置并行度

        //从集合中读取数据
        DataStream<SensorReading> dataStream = executionEnvironment.fromCollection(Arrays.asList(
                new SensorReading("sensor_1", 1547718199L, 35.8),
                new SensorReading("sensor_6", 1547718201L, 15.4),
                new SensorReading("sensor_7", 1547718202L, 6.7),
                new SensorReading("sensor_10", 1547718205L, 38.1)
        ));

        DataStreamSource<Integer> integerDataStreamSource = executionEnvironment.fromElements(1, 2, 3, 4, 5);


        //打印输出
        dataStream.print("data");
        integerDataStreamSource.print("int");

        //执行
        executionEnvironment.execute();



    }

}
